//
//  MKPersonalCenterViewController.m
//  singForYou
//
//  Created by nicolas on 2017/3/7.
//  Copyright © 2017年 nicolas. All rights reserved.
//

#import "MKPersonalCenterViewController.h"
#import "MKTestViewController.h"
#import "MKLoginViewController.h"
@interface MKPersonalCenterViewController ()

@end

@implementation MKPersonalCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIButton *overBtn = [[UIButton alloc] initWithFrame:CGRectMake(80, 100, 80, 40)];
    [self.view addSubview: overBtn];
    [overBtn setTitle:@"注销" forState:UIControlStateNormal];
    [overBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [overBtn addTarget:self action:@selector(overBackToLogin) forControlEvents:UIControlEventTouchUpInside];
   
}

- (void)overBackToLogin {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注销" message:@"是否真需要注销" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *loginoutAction = [UIAlertAction actionWithTitle:@"注销" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        NSUserDefaults *userDefualt = [NSUserDefaults standardUserDefaults];
        [userDefualt setBool:NO forKey:@"isAutoLoginKey"];
        
        MKLoginViewController *loginVc = [UIStoryboard storyboardWithName:@"MKLoginSb" bundle:nil].instantiateInitialViewController;
        [[UIApplication sharedApplication].delegate window].rootViewController = loginVc;
    }];
    
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    //3.添加功能按钮
    [alert addAction:loginoutAction];
    [alert addAction:cancleAction];
    
    //4.弹出提示框
    [self presentViewController:alert animated:YES completion:nil];
}

@end
